<!DOCTYPE html>
<html lang="en">
<head>
    <title></title>
</head>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script src="/js/jquery/jquery.min.js"></script>
<script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
    input.error {
        border: 0px solid #ac2925;
    }
</style>
<body>
<div class="container">
    <form id="updateProblemForm">
        <br/>
        <div class="form-group">
            <label for="username">试题编号：</label>
            <input type="text" class="form-control" id="pro_id" name="username" value="${problem.pro_id}" >
        </div>
        <div class="form-group">
            <label for="username">题目：</label>
            <input type="text" class="form-control" id="pro_name" name="username" value="${problem.pro_name}" placeholder="输入修改内容">
        </div>
        <div class="form-group"  id="choiceMap">
            <label for="username">选项：</label>
            <div id="choice" v-if="">
                <input type="text" class="form-control" id="pro_choiceA" name="userage" value="A&nbsp;${problem.pro_mapname.A}" placeholder="输入修改内容">
                <input type="text" class="form-control" id="pro_choiceB"  name="userage" value="B&nbsp;${problem.pro_mapname.B}" placeholder="输入修改内容">
                <input type="text" class="form-control" id="pro_choiceC" name="userage"  value="C&nbsp;${problem.pro_mapname.C}" placeholder="输入修改内容">
                <input type="text" class="form-control" id="pro_choiceD"  name="userage" value="D&nbsp;${problem.pro_mapname.D}" placeholder="输入修改内容">
            </div>
            <div class="form-group"  id="choices1">
                <input type="text" class="form-control" id="pro_choiceE" name="userage"  value="E&nbsp;${problem.pro_mapname.E}" placeholder="输入修改内容">
            </div>
            <div class="form-group"  id="choices2">
                <input type="text" class="form-control" id="pro_choiceF"  name="userage" value="F&nbsp;${problem.pro_mapname.F}" placeholder="holder="输入修改内容">
            </div>
                <div class="form-group"  id="judge" v-if="">
                    <input type="text" class="form-control" id="pro_choiceF" name="userage"  value="F &nbsp;${problem.pro_mapname.F}" placeholder="输入修改内容">
                    <input type="text" class="form-control" id="pro_choiceT"  name="userage" value="T &nbsp;${problem.pro_mapname.T}" placeholder="输入修改内容">
            </div>
        </div>
         </div id="layimg" v-if="${problem.pro_mapname.A}!=''">
              <img  src="${problem.pro_mapname.A}" class="thumbnail" style="width:200px"
              >
          <div>
         <div class="form-group">
            <label for="username">题类型:</label>
            <select id="type_id">
                <option  id="type" selected="selected" value="${problem.type.type_name}" >${problem.type.type_name}</option>
                <#list  listType as listType>
                <option value="${listType.type_id}">${listType.type_name}</option>
                </#list>
            </select>
        </div>
        <div class="form-group">
            <label for="username">所属知识点：</label>
            <select id="point_id">
                <option selected="selected" value="${problem.point.point_id}">${problem.point.point_name}</option>
            <#list  listPoint as listPoint>
                <option value="${listPoint.point_id}">${listPoint.point_name}</option>
            </#list>
            </select>
        </div>
        <div class="form-group">
            <label for="username">等级难度：</label>
            <input type="text" class="form-control" id="grade" name="username" value="${problem.grade}"
                   placeholder="输入修改内容">
            </div>
            <div class="form-group">
                <label for="username">出题人：</label>
                <select id="teacher_id">
                    <option selected="selected" value="${problem.teacher.teacher_name}">${problem.teacher.teacher_name}</option>
                <#list  listTeacher as listTeacher>
                    <option value="${listTeacher.teacher_id}">${listTeacher.teacher_name}</option>
                </#list>
                </select>
                </div>
        <div class="form-group">
            <label for="username">出题时间：</label>
            <input type="text" class="form-control" id="date" name="username" value="${problem.date}"
                   placeholder="输入修改内容">
        </div>

        <div class="form-group">
                    <label for="username">所属题库：</label>
            <select id="lib_id">
                <option selected="selected" value="${problem.lib.lib_id}">${problem.lib.lib_name}</option>
            <#list  listLib as listLib>
                <option value="${listLib.lib_id}">${listLib.lib_name}</option>
            </#list>
            </select>
                </div>
         <div class="form-group">
            <label for="username">答案：</label>
            <input type="text" class="form-control" id="p_true" name="username" value="${problem.p_true}" placeholder="输入修改内容">
        </div>

        <div class="form-group">
            <label for="username">答案解析：</label>
            <input type="text" class="form-control" id="true_res" name="username" value="${problem.true_res}" placeholder="输入修改内容">
        </div>

        <div class="form-group">
            <label for="true_hot">热度：</label>
            <input type="text" class="form-control" id="true_hot" name="username" value="${problem.true_hot}" placeholder="输入修改内容">
        </div>

        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">修改</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
<script>
    var n=${mapSize};
    var t="${problem.type.type_name}";/*题类型*/
    var updateProblem = function (){
        //如果不符合校验规则，就返回
        if (!check().form()) {
            return;
        }
       /* 单选*/
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "/problem/updateChoice.do",
            data: {
                "pro_id":${problem.pro_id},
                "pro_name": $("#pro_name").val(),
                "pro_choiceA": $("#pro_choiceA").val(),
                "pro_choiceB": $("#pro_choiceB").val(),
                "pro_choiceC": $("#pro_choiceC").val(),
                "pro_choiceD": $("#pro_choiceD").val(),
                "type.type_id":$("#type_id option:selected").val(),
                "point.point_id":$("#point_id  option :selected").val(),
                "grade":$("#grade").val(),
                "teacher.teacher_id":$("#teacher_id option:selected").val(),
                "date":$("#date").val(),
                "lib.lib_id":$("#lib_id option :selected").val(),
                "p_true":$("#p_true").val,
                "true_res":$("#true_res").val(),
                "true_hot":$("#true_hot").val()
            },
            success: function () {
                $("#cancelBtn").click();
            }
        });
      /*  多选*/
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "/problem/updateChoices.do",
            data: {
                "pro_id":${problem.pro_id},
                "pro_name": $("#pro_name").val(),
                "pro_choiceA": $("#pro_choiceA").val(),
                "pro_choiceB": $("#pro_choiceB").val(),
                "pro_choiceC": $("#pro_choiceC").val(),
                "pro_choiceD": $("#pro_choiceD").val(),
                "pro_choiceE": $("#pro_choiceD").val(),
                "pro_choiceF": $("#pro_choiceD").val(),
                "type.type_id":$("#type_id option:selected").val(),
                "point.point_id":$("#point_id  option :selected").val(),
                "grade":$("#grade").val(),
                "teacher.teacher_id":$("#teacher_id option:selected").val(),
                "date":$("#date").val(),
                "lib.lib_id":$("#lib_id option :selected").val(),
                "p_true":$("#p_true").val,
                "true_res":$("#true_res").val(),
                "true_hot":$("#true_hot").val()
            },
            success: function () {
                $("#cancelBtn").click();
            }
        });
        /* 判断*/
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "/problem/updateJudge.do",
            data: {
                "pro_id":${problem.pro_id},
                "pro_name": $("#pro_name").val(),
                "pro_choiceF": $("#pro_choiceF").val(),
                "pro_choiceT": $("#pro_choiceT").val(),
                "type.type_id":$("#type_id option:selected").val(),
                "point.point_id":$("#point_id  option :selected").val(),
                "grade":$("#grade").val(),
                "teacher.teacher_id":$("#teacher_id option:selected").val(),
                "date":$("#date").val(),
                "lib.lib_id":$("#lib_id option :selected").val(),
                "p_true":$("#p_true").val,
                "true_res":$("#true_res").val(),
                "true_hot":$("#true_hot").val()
            },
            success: function () {
                $("#cancelBtn").click();
            }
        });
    }
    $("#saveBtn").on("click", function (){
        updateProblem();
    });

    $("#cancelBtn").on("click", function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getProblemPageList();
        parent.layer.close(index);
    });
    function check() {
        return $("#updateProblemForm").validate({
            rules: {
                username: {
                    required: true
                }
            },
            messages: {
                username: {
                    required: ""
                }
            }
        });
    }
    function hid (){
        if (t == "判断题") {
           $("#choiceMap #choice").hide();
            $("#choiceMap #choices1").hide();
            $("#choiceMap #choices2").hide();
        } else if (t == "单选题") {
            $("#choiceMap #choices1").hide();
            $("#choiceMap #choices2").hide();
            $("#choiceMap #judge").hide();
        } else if(t == "多选题") {
            if (n == 4) {
                $("#choiceMap #choices1").hide();
                $("#choiceMap #choices2").hide();
                $("#choiceMap #judge").hide();
            } else if (n == 5) {
                $("#choiceMap #choices2").hide();
                $("#choiceMap #judge").hide();
            } else {
                $("#choiceMap #judge").hide();
            }
        }
       }
    hid();
    function licolor() {
        $("li").css("background")
        backgroundClip
    }
</script>
</body>
</html>
